package cn.rxmind.dlicense.server.base;

import cn.rxmind.dlicense.core.exception.DLicenseErrEnum;
import cn.rxmind.dlicense.core.exception.DLicenseException;
import lombok.Data;

/**
 *
 * @description 全局接口响应结果
 *
 * @author renxin
 *
 * @email renxinzhiliangzhi@163.com
 * 
 * @date 2019/7/25 15:22
 */
@Data
public class BaseResult<T> {

    private Integer code;

    private String message;

    private T data;

    private BaseResult(){}

    public static BaseResult buildWithUtryLicenseException(DLicenseException e){

        BaseResult build = build();
        build.setCode(e.getCode());
        build.setMessage(e.getMessage());
        return build;

    }

    public static  <R>BaseResult<R> build(R data){

        BaseResult<R> result = build();
        result.setData(data);
        return result;

    }

    public static BaseResult build(DLicenseErrEnum dLicenseErrEnum, String message){

        BaseResult result =  new BaseResult();
        result.setCode(dLicenseErrEnum.getCode());
        result.setMessage(message);

        return result;
    }

    public static BaseResult build(){

        BaseResult result =  new BaseResult();
        result.setCode(DLicenseErrEnum.SUCCESS.getCode());
        result.setMessage(DLicenseErrEnum.SUCCESS.getMessage());

        return result;
    }

    public static BaseResult build (DLicenseErrEnum dLicenseErrEnum){

        BaseResult result =  new BaseResult();
        result.setCode(dLicenseErrEnum.getCode());
        result.setMessage(dLicenseErrEnum.getMessage());

        return result;
    }

}
